#include "cybertron/sensor/noise/WhiteNoise.hpp"
#include <algorithm>

CYBERTRON_BEGIN

WhiteNoise::WhiteNoise(float mu/* = 0.0*/, float sigma/* = 1.0*/)
	: NoiseBase(EWhiteNoise)
{
	m_distributions[0] = std::normal_distribution<float>(mu, sigma);
	m_distributions[1] = std::normal_distribution<float>(mu, sigma);
	m_distributions[2] = std::normal_distribution<float>(mu, sigma);
}

WhiteNoise::WhiteNoise(float mu, float sigma, float muAltitude, float sigmaAltitude)
	: NoiseBase(EWhiteNoise)
{
	m_distributions[0] = std::normal_distribution<float>(mu, sigma);
	m_distributions[1] = std::normal_distribution<float>(mu, sigma);
	m_distributions[2] = std::normal_distribution<float>(muAltitude, sigmaAltitude);
}

WhiteNoise::WhiteNoise(float mu0, float sigma0, float mu1, float sigma1, float mu2, float sigma2)
	: NoiseBase(EWhiteNoise)
{
	m_distributions[0] = std::normal_distribution<float>(mu0, sigma0);
	m_distributions[1] = std::normal_distribution<float>(mu1, sigma1);
	m_distributions[2] = std::normal_distribution<float>(mu2, sigma2);
}

WhiteNoise::~WhiteNoise()
{
}

vec3 WhiteNoise::update() {
	m_value = vec3(m_distributions[0](randomEngine()), m_distributions[1](randomEngine()), m_distributions[2](randomEngine()));
	return m_value;
}

float WhiteNoise::getMean(std::uint32_t index)
{
	index = std::min(index, 2u);
	return m_distributions[index].mean();
}

float WhiteNoise::getSigma(std::uint32_t index)
{
	index = std::min(index, 2u);
	return m_distributions[index].stddev();
}

CYBERTRON_END